package com.cainli.szbus.data.service;

import android.content.Intent;
import android.os.Bundle;

import com.cainli.szbus.data.operation.BusLineListOperation;
import com.cainli.szbus.data.operation.BusStatListOperation;
import com.cainli.szbus.data.requestmanager.RequestFactory;
import com.foxykeep.datadroid.exception.CustomRequestException;
import com.foxykeep.datadroid.requestmanager.Request;
import com.foxykeep.datadroid.service.RequestService;

/**
 * This class is called by the {@link SZBusRequestManager} through the {@link Intent} system.
 * @author cainli
 *
 */
public final class SZBusRequestService extends RequestService {

    @Override
    protected int getMaximumNumberOfThreads() {
        return 3;
    }

    @Override
    public Operation getOperationForType(int requestType) {
        switch (requestType) {
            case RequestFactory.REQUEST_TYPE_BUSLINE_LIST:
                return new BusLineListOperation();
            case RequestFactory.REQUEST_TYPE_BUSSTATS_LIST:
            	return new BusStatListOperation();
        }
        return null;
    }

    @Override
    protected Bundle onCustomRequestException(Request request, CustomRequestException exception) {
//        if (exception instanceof MyCustomRequestException) {
//            Bundle bundle = new Bundle();
//            bundle.putString(PoCRequestFactory.BUNDLE_EXTRA_ERROR_MESSAGE,
//                    "MyCustomRequestException thrown.");
//            return bundle;
//        }
        return super.onCustomRequestException(request, exception);
    }
}
